package tjs.study.notes.dotest.jvm.class_6_1_类文件结构.测试内存溢出;

import tjs.study.notes.dotest.jvm.class_6_1_类文件结构.DoTestOfStructure;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by Nicky.Tang on 2021/10/12 10:31 上午
 *
 * @since 02.12.10
 */
public class DoTestOfMemoryOut {
    /**
     * -XX:+HeapDumpOnOutOfMemoryError -Xms1m -Xmx1m -XX:MetaspaceSize=8m -XX:MaxMetaspaceSize=8m
     *
     * @param args
     * @throws Exception
     */
//    -Xms4m -Xmx4m
//    public static  final byte[] bytes = new byte[2014*1024];
//    public static  final int[] bytes = new int[510*1024];//int = 4个字节
//    public static  final Integer[] bytes = new Integer[510*1024];//int = 4个字节
//    public static  final long[] bytes = new long[252*1024];//long = 8个字节
//    public static  final DoTestOfStructure[] bytes = new DoTestOfStructure[511*1024];
    public static void main(String[] args) throws Exception {
//        System.out.println(bytes.length);
//        initTestStringStaticPool();
//        initTestEnity();
//        TestOutMemoryEntity testOutMemoryEntity = new TestOutMemoryEntity();
//        System.out.println(testOutMemoryEntity.a4000);
    }

    /**
     * Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
     * 字符串常量池位于堆中
     */
    public static void initTestStringStaticPool() {
        String str = "1234567890" + "333";
        while (true) {
            str = new String(str + str).intern();
        }
    }

//    public static void initTestEnity() {
//        int maxSize = 9999;
//        StringBuilder res = new StringBuilder();
//        for (int i = 128; i <= maxSize; i++) {
//            String field = "public static Integer a" + i + " = new Integer(" + i + ");";
//            res.append(field).append("\n");
//        }
////        System.out.println(res);
//        TjsStudyNotesApplication.writeClassToDisk("tjs.study.notes.dotest.jvm.class_6_1_类文件结构.TestOutOfMemory", res.toString().getBytes());
//    }


}
